*** Markup, market share and marginal cost + IV energy
* Bustein, Carvalho and Grassi

****************************** 1. Preamble ******

* clean up 
	clear all 
	macro drop _all
	set max_memory 50g
	set matsize 11000

*set working directory. 
	*cd "C:\Users\Public\Documents\BCG_DGM\"
	cd "C:\Users\Public\Documents\BCG_DGM\BCG\replication_file_jan25_package"


****************************************CHANGE SPECS AND OUTLIER ***************	
local specsDeta_l    _baseline
local winlevel_l    03 
********************************************************************************

**********************CHOICE of outliuer treatment level
* winsorization level 
global winlevel_gl `winlevel_l'
di "winlevel_gl=$winlevel_gl"

*trimmeing level (thousands)
if "`winlevel_l'"=="01"{
	global toptr_gl 990
	global bottr_gl 10
}
else if "`winlevel_l'"=="015"{
	global toptr_gl 985
	global bottr_gl 15
}
else if "`winlevel_l'"=="02"{
	global toptr_gl 980
	global bottr_gl 20
}
else if "`winlevel_l'"=="025"{
	global toptr_gl 975
	global bottr_gl 25
}
else if "`winlevel_l'"=="03"{
	global toptr_gl 970
	global bottr_gl 30
}

di "toptr_gl = $toptr_gl"
di "toptr_gl = $bottr_gl"

*global specsDeta ☺☺
global specsDeta `specsDeta_l'
di "specsDeta (global)==$specsDeta"	

di "results ending in  _$winlevel_gl$specsDeta" 



	* select dataset with production data 
	global dataset "ficusfare_reduced_9419_sec2_v0222"
	local indlist 08 13 14 15 16 17 18 20 22 23 24 25 26 27 28 29 30 31 32 33 43 46 70 95
	
	
	di "data=$dataset"
	
	di "==================================="
	
	
******************************************************************************************
****************************** 2. Load the data ******
******************************************************************************************
	
*select path
cd "C:\Users\Public\Documents\BCG_DGM\BCG\replication_file_jan25_package"

*load the firm-level data:
use data/$dataset, clear 

*merge with the estimation sample
	merge 1:1 firmsId year using "data\data_smallest_for_python$specsDeta.dta" 

	rename _merge merge_price


**drop some useless variables
capture drop acha1 acha2 acha3 acha5 acha6 cogs cogs_newdef acha1R acha2R acha3R acha5R acha6R  invcorp catotal_tot
capture drop sale v k m o s p q

**destring the sector code before the merge
destring naf2d, replace


*merge with the energy data
	merge m:1 naf2d year using "data/eacei_sector2dlevel.dta"

	rename _merge merge_energy

	drop if merge_energy==2
	
	
*Compute marginal cost proxy from energy 
	**compute material share in revenue
	gen mat_share= acha4/catotal
	
	
		
*Compute marginal cost proxy from energy with lag share
xtset firmsId year
	
	**MC proxy with material share in revenue 
	
		gen mc_ene_gene2_hat_lag = L.mat_share * lPmat_hat_lag_gene2
		
		
	
	
*Compute Markup 

	** define production variables
	gen s = ln(catotalR)
	gen m = ln(acha4R)	//m will be the variable input 
	gen v = ln(salR)
	gen k = ln(immocorR)
	gen o = ln(autachaR)

	** define cost ratio 
	gen ratio = catotal/acha4 
	
	**Loop over the quantity and revenu markup
	foreach specs in FSQ   {
		***merge coefficients 
		merge m:1 naf2d using "data\coefficients_byind_Python_`specs'$specsDeta.dta", nogen
		
		***rename coefficients 
		foreach beta in const_cd m_cd v_cd o_cd k_cd const_tl m_tl v_tl o_tl k_tl m2_tl mv_tl mo_tl mk_tl v2_tl vo_tl vk_tl o2_tl ok_tl k2_tl {
			rename beta_`beta' beta_`beta'_`specs'
		}
		
		***drop redundant variables
		drop N med_CD med_TL iqr_CD iqr_TL  rho_cd  rho_tl 
		
		
		***calculate elasticity - TL 
		gen elast_tl_s`specs'_t1 = beta_m_tl_`specs'	 				 	 + 	/// 
													2*beta_m2_tl_`specs'*m   + 	///
													  beta_mv_tl_`specs'*v 	 +	///
													  beta_mo_tl_`specs'*o 	 +	///
													  beta_mk_tl_`specs'*k	 
												
		***define elasticity - CD 									
		gen elast_cd_s`specs'_t1 = beta_m_cd_`specs'
		
		
		***calculate markups 
		gen mu_sepcal_TL_s`specs'_t1 =  elast_tl_s`specs'_t1 * ratio 
		gen mu_sepcal_CD_s`specs'_t1 =  elast_cd_s`specs'_t1 * ratio
			
		***calculate log markups
		gen l_mu_sepcal_TL_s`specs'_t1 = log(mu_sepcal_TL_s`specs'_t1) 
		gen l_mu_sepcal_CD_s`specs'_t1 = log(mu_sepcal_CD_s`specs'_t1)
	}
	
	




************************************************************************************************************************************************************************************
******************************************************************* 3. Selecting Final Sample and Some indicators
************************************************************************************************************************************************************************************	
	
*Keep firms with positive VA	
	keep if va>0

*Keep firms with positive catotal and inputs
	keep if sample_firm_inputs==1

*Keep the relevent sectors
	keep if sample_sectors2==1 //should be no change
	keep if naf2d_num != 95 & naf2d_num != 70 //Two other sectors that we want to drop
	




*Some indicator of markup level (quantity)
	gen markup_pos = 0
	replace markup_pos = 1 if mu_sepcal_TL_sFSQ_t1 > 0





*Keep siren with more than one year
	bysort siren: egen count_siren=count(catotal)
	keep  if count_siren>1
	
	

*Summary Stats on elasticity of materials
su elast_tl_sFSQ_t1, d
	
*Market Share

	**Sector level revenue
	bysort naf_single year: egen catotal_total = total(catotal)
	
	**Market Share
	gen share5 = catotal/catotal_total
	

		

*Drop the non-price firms
keep if merge_price==3




******************************************************************************************
****************************** 4. Define Price and Quantity       ******************
******************************************************************************************		
	
	

**price
		gen p = ln(price_firm_std8_m2345_wm_wm)
		


**quantity
		gen q = log(catotalR) - p



	

**temporary save of data
save data/temp_price_markup_marginalcost.dta, replace
use data/temp_price_markup_marginalcost.dta, clear

		
	
******************************************************************************************
****************************** 4ter. Additional Restriction and variable definition ***********
******************************************************************************************	

	**Compute first difference in markup, price, and quantity
		***set up panel
		xtset firmsId year
		
		***Change format of 5-digit sector
		egen naf_single_num = group(naf_single)
		
		***FD
		foreach var in p q l_mu_sepcal_TL_sFSQ_t1  {
			gen FD_`var'  = `var'-L.`var'
		}
		/*
		foreach var in p q l_mu_sepcal_TL_sFSQ_t1  mc_ene_hat mc_ene_TEP_hat mc_ene_gene_hat mc_ene_gene2_hat {
			gen FD_`var'  = `var'-L.`var'
		}
		*/
		
		***FD for lagged
		gen FD_mc_ene_gene2_hat_lag  = mc_ene_gene2_hat_lag-L.mc_ene_gene2_hat_lag
		
	
	**Define (log) marginal cost
	gen mc_pmu = p - l_mu_sepcal_TL_sFSQ_t1

	**Define FD (log)  marginal cost
	gen FD_mc_pmu = FD_p - FD_l_mu_sepcal_TL_sFSQ_t1


	
	**Winsorized 
		local top_tr $toptr_gl
		local bot_tr $bottr_gl
		local winlevel $winlevel_gl
		
		***markups
		winsor  mu_sepcal_TL_sFSQ_t1 , p(.`winlevel') gen(mu_sepcal_TL_sFSQ_t1_w)
		
		
		***FD
		foreach var in p q l_mu_sepcal_TL_sFSQ_t1   {
				winsor   FD_`var', p(.`winlevel') gen(FD_`var'_w)
			}
		/*
		foreach var in p q l_mu_sepcal_TL_sFSQ_t1  mc_ene_hat mc_ene_TEP_hat mc_ene_gene_hat mc_ene_gene2_hat  {
				winsor   FD_`var', p(.`winlevel') gen(FD_`var'_w)
			}
		*/
			
		***FD for other energy prices
		local top_tr $toptr_gl
		local bot_tr $bottr_gl
		local winlevel $winlevel_gl
		
		winsor   FD_mc_ene_gene2_hat_lag, p(.`winlevel') gen(FD_mc_ene_gene2_hat_lag_w)
		winsor  mc_ene_gene2_hat_lag , p(.`winlevel') gen(mc_ene_gene2_hat_lag_w)
		
	
		
		***price and quantity
		winsor  p , p(.`winlevel') gen(p_w)
		winsor  q , p(.`winlevel') gen(q_w)
		
		***energy price 
		/*	
		foreach var in  mc_ene_hat mc_ene_TEP_hat mc_ene_gene_hat mc_ene_gene2_hat {
			winsor  `var' , p(.`winlevel') gen(`var'_w)
		}
		*/
		
		
		***marginal cost
		local top_tr $toptr_gl
		local bot_tr $bottr_gl
		local winlevel $winlevel_gl
		
			****level
			winsor  mc_pmu , p(.`winlevel') gen(mc_pmu_w)
			
			****FD
			winsor  FD_mc_pmu , p(.`winlevel') gen(FD_mc_pmu_w)

	
	
	**Taking Logs
		***winsorized markup
		gen l_mu_sepcal_TL_sFSQ_t1_w = log(mu_sepcal_TL_sFSQ_t1_w)
	
	
	
	**Summary stats
	su l_mu_sepcal_TL_sFSQ_t1 l_mu_sepcal_TL_sFSQ_t1_w
		
******************************************************************************************
****************************** 5.Markup, Marginal Cost and Price   ******************
******************************************************************************************



**Summary Stats on (log) marginal cost
su mc_pmu mc_pmu_w, d

gen minus_mc_pmu = -mc_pmu
gen minus_mc_pmu_w = -mc_pmu_w

su FD_mc_pmu FD_mc_pmu_w, d


*Regression	

	**markup marginal cost	
		***level
		reghdfe l_mu_sepcal_TL_sFSQ_t1_w mc_pmu_w    , noabsorb  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\markup_mc_$winlevel_gl$specsDeta , replace tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe l_mu_sepcal_TL_sFSQ_t1_w mc_pmu_w    ,  absorb(year)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\markup_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, Yes, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe l_mu_sepcal_TL_sFSQ_t1_w mc_pmu_w    , absorb(year#naf_single_num)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\markup_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, Yes, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe l_mu_sepcal_TL_sFSQ_t1_w mc_pmu_w    , absorb(firmsId)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\markup_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, No, Firm FE, Yes, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe l_mu_sepcal_TL_sFSQ_t1_w mc_pmu_w    , absorb(firmsId year)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\markup_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, Yes, Market*Year FE, No, Firm FE, Yes, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe l_mu_sepcal_TL_sFSQ_t1_w mc_pmu_w    , absorb(firmsId year#naf_single_num)  cl(year firmsId) 
		outreg2 using BCG\results\markup_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, Yes, Firm FE, Yes, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
	

		***FD
		reghdfe FD_l_mu_sepcal_TL_sFSQ_t1_w FD_mc_pmu_w     , noabsorb  cl(year firmsId)  tech(lsmr)
		outreg2 using BCG\results\FDmarkup_FDmc_$winlevel_gl$specsDeta , replace tex   keep(FD_mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe FD_l_mu_sepcal_TL_sFSQ_t1_w FD_mc_pmu_w     , absorb(year)  cl(year firmsId)  tech(lsmr)
		outreg2 using BCG\results\FDmarkup_FDmc_$winlevel_gl$specsDeta , append tex   keep(FD_mc_pmu_w) addtext(Market FE, No, Year FE, Yes, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe FD_l_mu_sepcal_TL_sFSQ_t1_w FD_mc_pmu_w    , absorb(year#naf_single_num)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\FDmarkup_FDmc_$winlevel_gl$specsDeta , append tex   keep(FD_mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, Yes, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		

		

	**market share marginal cost
		***level
		gen lshare5 = log(share5)
		
		
		reghdfe lshare5 mc_pmu_w    , noabsorb  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\marketshare_mc_$winlevel_gl$specsDeta , replace tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe lshare5 mc_pmu_w    ,  absorb(year)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\marketshare_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, Yes, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe lshare5 mc_pmu_w    , absorb(year#naf_single_num)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\marketshare_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, Yes, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe lshare5 mc_pmu_w    , absorb(firmsId)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\marketshare_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, No, Firm FE, Yes, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
	
		reghdfe lshare5 mc_pmu_w    , absorb(firmsId year)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\marketshare_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, Yes, Market*Year FE, No, Firm FE, Yes, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe lshare5 mc_pmu_w    , absorb(firmsId year#naf_single_num)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\marketshare_mc_$winlevel_gl$specsDeta , append tex   keep(mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, Yes, Firm FE, Yes, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
	

			
		
		***FD
		xtset firmsId year
		gen FD_lshare5 = lshare5 - L.lshare5
		
		
		reghdfe FD_lshare5 FD_mc_pmu_w     , noabsorb  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\FDmarketshare_FDmc_$winlevel_gl$specsDeta , replace tex   keep(FD_mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe FD_lshare5 FD_mc_pmu_w     , absorb( year)  cl(year firmsId) 
		outreg2 using BCG\results\FDmarketshare_FDmc_$winlevel_gl$specsDeta , append tex   keep(FD_mc_pmu_w) addtext(Market FE, No, Year FE, Yes, Market*Year FE, No, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		reghdfe FD_lshare5 FD_mc_pmu_w    , absorb(year#naf_single_num)  cl(year firmsId) tech(lsmr)
		outreg2 using BCG\results\FDmarketshare_FDmc_$winlevel_gl$specsDeta , append tex   keep(FD_mc_pmu_w) addtext(Market FE, No, Year FE, No, Market*Year FE, Yes, Firm FE, No, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)' )
		
		


		 
		 
*********************** Produce Tables for IV


*Baseline specs

	*Choose your instrument (baseline = mc_ene_gene2_hat_lag_w )
	local mc_iv mc_ene_gene2_hat_lag_w
		
	*Baseline FD specs

		**first stage
		reghdfe FD_mc_pmu_w   FD_`mc_iv'    , noabsorb  cl(year firmsId)
		outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , replace tex  ctitle(First) keep(FD_`mc_iv') addtext(Spec, First-Stage , Instu, FD_`mc_iv' , Market FE, N, Year FE, N, Market*Year FE, N, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(F)' )
		
		reghdfe FD_mc_pmu_w   FD_`mc_iv'    , absorb(year)  cl(year firmsId)
		outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(First) keep(FD_`mc_iv') addtext(Spec, First-Stage, Instu, FD_`mc_iv' , Market FE, N, Year FE, Y, Market*Year FE, N, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(F)' )
		
		reghdfe FD_mc_pmu_w   FD_`mc_iv'    , absorb(year#naf_single_num)  cl( year firmsId) 
		outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(First) keep(FD_`mc_iv') addtext(Spec, First-Stage, Instu, FD_`mc_iv' , Market FE, N, Year FE, N, Market*Year FE, Y, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(F)' )



		**IV regression 
			**market share
			ivreghdfe FD_lshare5 (FD_mc_pmu_w  = FD_`mc_iv')    , noabsorb  cl(year firmsId)
			outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(IV) keep(FD_mc_pmu_w) addtext(Spec, IV, Instu, FD_`mc_iv' , Market FE, N, Year FE, N, Market*Year FE, N, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(widstat)' )
			
			ivreghdfe FD_lshare5 (FD_mc_pmu_w  = FD_`mc_iv')    , absorb(year)  cl(year firmsId)
			outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(IV) keep(FD_mc_pmu_w) addtext(Spec, IV, Instu, FD_`mc_iv' , Market FE, N, Year FE, Y, Market*Year FE, N, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(widstat)' )
			
			ivreghdfe FD_lshare5 (FD_mc_pmu_w  = FD_`mc_iv')    , absorb(year#naf_single_num)  cl(year firmsId)
			outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(IV) keep(FD_mc_pmu_w) addtext(Spec, IV, Instu, FD_`mc_iv' , Market FE, N, Year FE, N, Market*Year FE, Y, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(widstat)' )

		
		**markup

			ivreghdfe FD_l_mu_sepcal_TL_sFSQ_t1_w (FD_mc_pmu_w  = FD_`mc_iv')   , noabsorb  cl(year firmsId)
			outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(IV) keep(FD_mc_pmu_w) addtext(Spec, IV, Instu, FD_`mc_iv' , Market FE, N, Year FE, N, Market*Year FE, N, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(widstat)' )
			
			ivreghdfe FD_l_mu_sepcal_TL_sFSQ_t1_w (FD_mc_pmu_w  = FD_`mc_iv')   , absorb(year)  cl(year firmsId)
			outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(IV) keep(FD_mc_pmu_w) addtext(Spec, IV, Instu, FD_`mc_iv' , Market FE, N, Year FE, Y, Market*Year FE, N, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(widstat)' )
			
			ivreghdfe FD_l_mu_sepcal_TL_sFSQ_t1_w (FD_mc_pmu_w  = FD_`mc_iv')   , absorb(year#naf_single_num)  cl(year firmsId)
			outreg2 using BCG\results\mc_IV_`mc_iv'_$winlevel_gl$specsDeta , append tex  ctitle(IV) keep(FD_mc_pmu_w) addtext(Spec, IV, Instu, FD_`mc_iv' , Market FE, N, Year FE, N, Market*Year FE, Y, Firm FE, N, Cluster , Firm Year, R2, `: di %9.3f e(r2)', adj-R2, `: di %9.3f e(r2_a)',  with-R2, `: di %9.3f e(r2_within)',  with-adj-R2, `: di %9.3f e(r2_a_within)',  F-stat First, `: di %9.3f e(widstat)' )
		

	